<div id="main">
<?

//show the list of the ads here (the ads per user not all the ads that exists in the db)
$hostname_logon = 'localhost';      //Database server LOCATION
    $database_logon = 'wwwmsc_newcareer';       //Database NAME
    $username_logon = 'wwwmsc';       //Database USERNAME
    $password_logon = 'Slpnxhe}bX4h';       //Database PASSWORD
	$database_connection = mysql_connect($hostname_logon,$username_logon,$password_logon) or die("couldnt connect with mysql");
	$database_selection = mysql_select_db($database_logon,$database_connection);
	mysql_query( "SET NAMES utf8", $database_connection );
        mysql_query( "SET CHARACTER SET utf8", $database_selection );
	$mode = $_REQUEST["mode"];
	if($mode == "delete")
	{
		$ad_id = $_REQUEST["ad_id"];
		$ad_delete_query = "delete from ADS where ad_id = '$ad_id' limit 1";
		$ad_delete_result = mysql_query($ad_delete_query) or die(mysql_error());
	}
	$ad_select_query = "select * from ADS where ad_userid = '".$_SESSION['userid']."'";
	$ad_select_result = mysql_query($ad_select_query) or die(mysql_error());
	$ad_select_total = mysql_num_rows($ad_select_result);
	if($ad_select_total > 0)
	{
		echo '<table width="850" border="1" align="center"><tr>
                <th>ID</th>
                <th>Title</th>
                <th>Description</th>
                <th>Code</th>
                <th>Type</th>
                <th>Date</th>
                <th>Email</th>
                <th>Category Name</th>
                <th>Salary</th>
                <th>Address</th>
                <th>Edit</th>
                <th>Delete</th>
              </tr>';
		while($ad_select_data = mysql_fetch_array($ad_select_result))
		{
			$ad_id	=	$ad_select_data["ad_id"];
		 	$ad_title	=	$ad_select_data["ad_title"];
		 	$ad_desc	=	$ad_select_data["ad_desc"];
		 	$ad_code	=	$ad_select_data["ad_code"];
		 	$ad_type	=	$ad_select_data["ad_type"];
		 	$ad_date	=	$ad_select_data["ad_date"];
		 	$ad_email	=	$ad_select_data["ad_email"];
		 	$ad_locid	=	$ad_select_data["ad_locid"];
		 	$ad_catid	=	$ad_select_data["ad_catid"];
				$ad_catid	=	$ad_select_data["ad_catid"];
				$category_select_query = "select cat_desc from CATEGORIES WHERE `cat_id` = '$ad_catid' limit 1";
				$category_select_result = mysql_query($category_select_query) or die(mysql_error());
				$category_name = mysql_result($category_select_result,0);
				
		 	$ad_salary	=	$ad_select_data["ad_salary"];
		 	$ad_checked	=	$ad_select_data["ad_checked"];
			$user_autocomplete	=	$ad_select_data["user_autocomplete"];
			?>
              <tr>
                <td><?php echo $ad_id; ?></td>
                <td><?php echo $ad_title; ?></td>
                <td><?php echo $ad_desc; ?></td>
                <td><?php echo $ad_code; ?></td>
                <td><?php echo $ad_type; ?></td>
                <td><?php echo $ad_date; ?></td>
                <td><?php echo $ad_email; ?></td>
                <td><?php echo $category_name; ?></td>
                <td><?php echo $ad_salary; ?></td>
                <td><?php echo $user_autocomplete; ?></td>
                <td><input type="button" onclick='window.location.href = "portal.php?action=editAds&ad_id=<?php echo $ad_id; ?>"' value="Edit" /></td>
                <td><input type="button" onclick='window.location.href = "portal.php?action=showAds&ad_id=<?php echo $ad_id; ?>&mode=delete"' value="Delete" /></td>
              </tr>
            <?php
		}
		echo '</table>';
	}
	else
	{
	}
?>

</div>	